Skip to content

Fix: reduce MSSQL connections per collect; add unit tests#176

Merged
Rom1-B merged 2 commits into
mainfrom
fix_mssql_connection
May 26, 2026
Merged

Fix: reduce MSSQL connections per collect; add unit tests#176
Rom1-B merged 2 commits into
mainfrom
fix_mssql_connection

Conversation

@Rom1-B
Copy link
Copy Markdown
Contributor

@Rom1-B Rom1-B commented May 25, 2026

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

Each collect run was opening up to N*8 MSSQL connections (one per get*() method per device).
A single PluginSccmSccmdb is now created once per config in executeCollect() and passed to all per-device data fetching methods, reducing connections to 2 per config regardless of device count.
The set*() methods in PluginSccmSccmxml accept an optional ?PluginSccmSccm parameter for dependency injection, enabling a PHPUnit test suite covering query building, XML generation, and data transformation logic (47 tests, 209 assertions).

@Rom1-B Rom1-B requested a review from stonebuzz May 25, 2026 07:48
@Rom1-B Rom1-B mentioned this pull request May 25, 2026
4 tasks
@Rom1-B Rom1-B marked this pull request as draft May 25, 2026 08:02
@tolemac
Copy link
Copy Markdown
Contributor

tolemac commented May 25, 2026

@Rom1-B Tell me when I can test it in my environment.

@Rom1-B
Copy link
Copy Markdown
Contributor Author

Rom1-B commented May 26, 2026

@tolemac
You can test it in a test environment

@stonebuzz stonebuzz force-pushed the fix_mssql_connection branch from afbfe9b to 7559a12 Compare May 26, 2026 07:09
@Rom1-B Rom1-B marked this pull request as ready for review May 26, 2026 07:17
@tolemac
Copy link
Copy Markdown
Contributor

tolemac commented May 26, 2026

Tested!

Now is faster:

[Config 1] getDevices OK - 274 files
2026-05-26 09:24:09 [473@SUInventario]
[Config 1] Collect OK for device - 16784352
2026-05-26 09:24:10 [473@SUInventario]
[Config 1] Collect OK for device - 16784363
2026-05-26 09:24:10 [473@SUInventario]
[Config 1] Collect OK for device - 16784374
2026-05-26 09:24:10 [473@SUInventario]
[Config 1] Collect OK for device - 16784381
2026-05-26 09:24:11 [473@SUInventario]
[Config 1] Collect OK for device - 16784383
2026-05-26 09:24:11 [473@SUInventario]

Several items by second, good job!

@Rom1-B Rom1-B merged commit e61152e into main May 26, 2026
3 checks passed
@Rom1-B Rom1-B deleted the fix_mssql_connection branch May 26, 2026 10:22
@tolemac
Copy link
Copy Markdown
Contributor

tolemac commented May 26, 2026

Nice, do you plan a new release with all last changes??
I think it would be appropriate.

@tolemac
Copy link
Copy Markdown
Contributor

tolemac commented May 26, 2026

Perhaps with #167 ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants